`
https://leetcode.cn/problems/find-the-town-judge/
`

/**
 * @param {number} n
 * @param {number[][]} trust
 * @return {number}
 */
var findJudge = function (n, trust) {
  // 求出入度和出度
  const indegree = new Array(n + 1).fill(0)
  const outdegree = new Array(n + 1).fill(0)
  for (const edge of trust) {
    const from = edge[0], to = edge[1]
    outdegree[from]++
    indegree[to]++
  }

  // 寻找入度为 n - 1 且入度为 0 的人
  for (let i = 1; i <= n; i++) {
    if (indegree[i] === n - 1 && outdegree[i] === 0) {
      return i
    }
  }

  // 没找到
  return -1
};